package svc

import (
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"navi-mumbai/app/rpc/model/pg/game"
	"navi-mumbai/app/rpc/model/pg/stat"
	"navi-mumbai/app/rpc/model/pg/usercenter"
	"navi-mumbai/app/rpc/model/pg/wallet"
	"navi-mumbai/app/rpc/stat/internal/config"
)

type ServiceContext struct {
	Config config.Config

	UserDailyLoginStatModel     stat.UserDailyLoginStatModel
	UserGameDailyOrderStatModel stat.UserGameDailyOrderStatModel
	UserDepositDailyStatModel   stat.UserDepositDailyStatModel
	UserWithdrawDailyStatModel  stat.UserWithdrawDailyStatModel
	UserLoginLogModel           stat.UserLoginLogModel
	LifeTimeValueModel          stat.LifeTimeValueModel

	UserAccountModel            usercenter.UserAccountModel
	UserLoginStatModel          usercenter.UserLoginStatModel
	UserDepositFlowModel        wallet.UserDepositFlowModel
	UserWithdrawFlowModel       wallet.UserWithdrawFlowModel
	UserGameOrderFlowModel      wallet.UserGameOrderFlowModel
	CurrencyExchangeConfigModel wallet.CurrencyExchangeConfigModel
	GameModel                   game.GameModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlConn := sqlx.NewMysql(c.StatDB.DataSource)                 //sqlx.NewSqlConn(dbkey.PostgresDriverName, c.StatDB.DataSource)
	sqlConnReadUc := sqlx.NewMysql(c.UserReadDB.DataSource)       //sqlx.NewSqlConn(dbkey.PostgresDriverName, c.UserReadDB.DataSource)
	sqlConnReadWallet := sqlx.NewMysql(c.WalletReadDB.DataSource) //sqlx
	sqlConnReadGame := sqlx.NewMysql(c.GameReadDB.DataSource)     /// .NewSqlConn(dbkey.PostgresDriverName, c.WalletReadDB.DataSource)
	return &ServiceContext{
		Config:                      c,
		UserDailyLoginStatModel:     stat.NewUserDailyLoginStatModel(sqlConn, c.Cache),
		UserGameDailyOrderStatModel: stat.NewUserGameDailyOrderStatModel(sqlConn, c.Cache),
		UserDepositDailyStatModel:   stat.NewUserDepositDailyStatModel(sqlConn, c.Cache),
		UserWithdrawDailyStatModel:  stat.NewUserWithdrawDailyStatModel(sqlConn, c.Cache),
		UserLoginLogModel:           stat.NewUserLoginLogModel(sqlConn, c.Cache),
		LifeTimeValueModel:          stat.NewLifeTimeValueModel(sqlConn, c.Cache),

		UserAccountModel:            usercenter.NewUserAccountModel(sqlConnReadUc, c.Cache),
		UserLoginStatModel:          usercenter.NewUserLoginStatModel(sqlConnReadUc, c.Cache),
		UserDepositFlowModel:        wallet.NewUserDepositFlowModel(sqlConnReadWallet, c.Cache),
		UserWithdrawFlowModel:       wallet.NewUserWithdrawFlowModel(sqlConnReadWallet, c.Cache),
		UserGameOrderFlowModel:      wallet.NewUserGameOrderFlowModel(sqlConnReadWallet, c.Cache),
		CurrencyExchangeConfigModel: wallet.NewCurrencyExchangeConfigModel(sqlConnReadWallet, c.Cache),
		GameModel:                   game.NewGameModel(sqlConnReadGame, c.Cache),
	}
}
